package com.bjc.principle.factorymethod.order;

import com.bjc.principle.factorymethod.pizza.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @program: DesignPattern
 * @description:
 * @author: bjc
 * @create: 2020-12-16 19:50
 */
public abstract class OrderPizza {

    //定义一个抽象方法，createPizza 让各个子工厂类自己实现
    abstract Pizza createPizza(String orderType);

    public OrderPizza() {
        Pizza pizza = null;
        String orderTypes; //订购披萨的类型
        do {
            orderTypes = getType();
            pizza = createPizza(orderTypes);  //抽象方法，由子类完成
            if (null!= pizza){
                //输出披萨制作过程
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                break;
            }
        }while (true);
    }

    //写一个方法，可以获取用户希望订购的披萨种类
    private String getType(){
        try{
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type");
            String s = strin.readLine();
            return s;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }
}
